package org.jackysoft.util;

import java.io.IOException;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class AbstractTagSupport extends BodyTagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6624648272431912886L;
	static final Log log = LogFactory.getLog(AbstractTagSupport.class);
	public static String FIRST_LINE = "firstLine";	
	
	protected String htmlProps;

	public void setHtmlProps(String htmlProps) {
		this.htmlProps = htmlProps;
	}

	protected void println(Object obj) {
		JspWriter out = pageContext.getOut();
		try {
			out.println(obj == null ? "" : obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void bprintln(Object obj) {
		JspWriter out = this.getBodyContent().getEnclosingWriter();
		try {
			out.println(obj == null ? "" : obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void setBodyContent(BodyContent b) {
		bodyContent = b;
	}

	public void setPageVar(String name, Object value) {
		pageContext.setAttribute(name, value);
	}

	public Object getPageVar(String name) {
		return pageContext.getAttribute(name);
	}

	public void setRequestVar(String name, Object value) {
		pageContext.getRequest().setAttribute(name, value);
	}

	public Object getRequestVar(String name) {
		Object value = pageContext.getRequest().getAttribute(name);
		return value == null ? "" : value;
	}

}